#coding: utf-8
import win32com.client
import time

repeatTimes = 5
delayForEachWords = 20

def startTest():
    try:
        spk = win32com.client.Dispatch("SAPI.SpVoice")
        spk.Speak("开始默写啦，请准备好！")
        with open("words.txt", mode = 'r', encoding='utf-8') as file:
            for word in file:
                for i in range(repeatTimes):
                    spk.Speak(word)
                    time.sleep(delayForEachWords/repeatTimes)        
    except Exception as e:
        print(e)

if __name__ == "__main__":
    startTest()
